package cn.itheima.manage.service;

import cn.itheima.manage.dao.StudentDao;
import cn.itheima.manage.domain.Student;

public class StudentService {
    private StudentDao studentDao = new StudentDao();

    public void updateStudent(String sid, Student stu) {
       studentDao.updateStudent(sid,stu);
    }

    public boolean addStudent(Student stu) {
       return studentDao.addStudent(stu);
    }

    public boolean isExists(String sid) {
        Student[] students = studentDao.findAllStudent();
        boolean exists = false;
        for (int i = 0; i < students.length; i++) {
            Student student = students[i];
            if(student!=null&&student.getId().equals(sid)){
                exists = true;
            }
        }
        return exists;
    }

    public Student[] findAllStudent() {
        Student[] students = studentDao.findAllStudent();

        boolean flag = false;
        for (int i = 0; i < students.length; i++) {
            Student student = students[i];
            if(student!=null){
                flag=true;
                break;
            }else {
                return null;
            }
        }
        return students;
    }

    public void deleteStudentBySid(String sid) {
        studentDao.deleteStudentBySid(sid);
    }
}
